/**
 * fileName: DaoActivityRecordToperImpl.java
 * fileTime: 2011-6-17下午10:18:52
 */
package com.bf.xpdd.persistent.sqlmapdao;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;

import com.bf.xpdd.domain.ActivityRecordToperBean;
import com.bf.xpdd.persistent.iface.DaoActivityRecordToper;
import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * 最低成交纪录实现
 * 
 * @author linmu
 * 
 */
public class DaoActivityRecordToperImpl implements DaoActivityRecordToper
{

	/**
	 * 日志记录器
	 */
	private Logger logger = Logger.getLogger(DaoActivityRecordToperImpl.class);

	/**
	 * ibatis的查询接口
	 */
	private SqlMapClient sqlMapClient;

	/**
	 * 注入sqlMapClient
	 * 
	 * @param sqlMapClient
	 */
	public void setSqlMapClient(SqlMapClient sqlMapClient)
	{
		this.sqlMapClient = sqlMapClient;
	}

	@Override
	public void addActivityRecordToper(ActivityRecordToperBean recordBean)
	{
		try
		{
			this.sqlMapClient.startTransaction();
			this.sqlMapClient.insert("actRecordToper.addActRecordToper", recordBean);
			this.sqlMapClient.commitTransaction();
		}
		catch (SQLException e)
		{
			this.logger.error(e.toString());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				this.sqlMapClient.endTransaction();
			}
			catch (SQLException e)
			{
				this.logger.error(e.toString());
				e.printStackTrace();
			}
		}

	}

	@Override
	public void delActRecordToper(long id)
	{
		try
		{
			this.sqlMapClient.startTransaction();
			this.sqlMapClient.delete("actRecordToper.delActRecordToperById", id);
			this.sqlMapClient.commitTransaction();
		}
		catch (SQLException e)
		{
			this.logger.error(e.toString());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				this.sqlMapClient.endTransaction();
			}
			catch (SQLException e)
			{
				this.logger.error(e.toString());
				e.printStackTrace();
			}
		}
	}

	@Override
	public void delActRecordToperByItemId(long itemId)
	{
		try
		{
			this.sqlMapClient.startTransaction();
			this.sqlMapClient.delete("actRecordToper.delActRecordToperByItemId", itemId);
			this.sqlMapClient.commitTransaction();
		}
		catch (SQLException e)
		{
			this.logger.error(e.toString());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				this.sqlMapClient.endTransaction();
			}
			catch (SQLException e)
			{
				this.logger.error(e.toString());
				e.printStackTrace();
			}
		}
	}

	@Override
	public void delActRecordToperByNick(String nick)
	{
		try
		{
			this.sqlMapClient.startTransaction();
			this.sqlMapClient.delete("actRecordToper.delActRecordToperByNick", nick);
			this.sqlMapClient.commitTransaction();
		}
		catch (SQLException e)
		{
			this.logger.error(e.toString());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				this.sqlMapClient.endTransaction();
			}
			catch (SQLException e)
			{
				this.logger.error(e.toString());
				e.printStackTrace();
			}
		}
	}

	@Override
	public ActivityRecordToperBean queryActRecordToperById(long id)
	{
		try
		{
			this.sqlMapClient.startTransaction();
			Object obj = this.sqlMapClient.queryForObject("actRecordToper.queryActRecordToperById",
					id);
			this.sqlMapClient.commitTransaction();
			return (ActivityRecordToperBean) obj;
		}
		catch (SQLException e)
		{
			this.logger.error(e.toString());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				this.sqlMapClient.endTransaction();
			}
			catch (SQLException e)
			{
				this.logger.error(e.toString());
				e.printStackTrace();
			}
		}
		return null;
	}

	@Override
	public List<ActivityRecordToperBean> queryActRecordToperByItemId(long itemId)
	{
		try
		{
			this.sqlMapClient.startTransaction();
			List<ActivityRecordToperBean> list = (List<ActivityRecordToperBean>) this.sqlMapClient
					.queryForList("actRecordToper.queryActRecordToperByItemId", itemId);
			this.sqlMapClient.commitTransaction();
			return list;
		}
		catch (SQLException e)
		{
			this.logger.error(e.toString());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				this.sqlMapClient.endTransaction();
			}
			catch (SQLException e)
			{
				this.logger.error(e.toString());
				e.printStackTrace();
			}
		}
		return null;
	}

	@Override
	public List<ActivityRecordToperBean> queryActRecordToperByNick(String nick)
	{
		try
		{
			this.sqlMapClient.startTransaction();
			List<ActivityRecordToperBean> list = (List<ActivityRecordToperBean>) this.sqlMapClient
					.queryForList("actRecordToper.queryActRecordToperByNick", nick);
			this.sqlMapClient.commitTransaction();
			return list;
		}
		catch (SQLException e)
		{
			this.logger.error(e.toString());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				this.sqlMapClient.endTransaction();
			}
			catch (SQLException e)
			{
				this.logger.error(e.toString());
				e.printStackTrace();
			}
		}
		return null;
	}

	@Override
	public double queryLeastPriceByItemId(long itemId)
	{
		try
		{
			this.sqlMapClient.startTransaction();
			Object obj =  this.sqlMapClient.queryForObject("actRecordToper.queryLeastPriceByItemId", itemId);
			this.sqlMapClient.commitTransaction();
			return ((Double)obj).doubleValue();
		}
		catch (SQLException e)
		{
			this.logger.error(e.toString());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				this.sqlMapClient.endTransaction();
			}
			catch (SQLException e)
			{
				this.logger.error(e.toString());
				e.printStackTrace();
			}
		}
		return -1;
	}

}
